﻿using System;
using System.Net.NetworkInformation;

namespace TianShu.LicenseAuthorizer.Abstracts
{
    public static class LiceseAuthorizerConst
    {
        public readonly static string DecryptKey = @"<RSAKeyValue><Modulus>3IVgbQQF02s2nOvVGsJF81CFYm8WGTVMVU6QVMJNwRYah/q8BZLuqhq/QSlN69ZO4fLONK014r1ZRk83s06Bx/vhHxs6tG9QkCIc5g4iN2Jv61n4irCZ8+FvcYyuzGxWFQIDBqh99HgKKFZs+dmAgl93pHqsnoz4qz/pZ6JfbGHChkcIrShH+4t4OR78DD4I9VN34FKLYzqHgKm0T+ypiEJxtpOO8uEXLipqM1YU8Yq/sERsFdTjmMmrGp+lNIHg8M6MMwb8l75T71BZBGbvne+7Agq4JCan6nTN3WrA/VMYOU6rYGB6ukGrdQUvCvXaojRkeWr0n7P/0x6Hcc755Q==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

        /// <summary>
        /// 获取电脑 MAC（物理） 地址
        /// </summary>
        /// <returns></returns>
        public static string GetMACIp()
        {
            //本地计算机网络连接信息
            IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
            //获取本机所有网络连接
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();

            //获取本机电脑名
            var HostName = computerProperties.HostName;
            //获取域名
            var DomainName = computerProperties.DomainName;

            if (nics == null || nics.Length < 1)
            {
                return "";
            }

            var MACIp = "";
            foreach (NetworkInterface adapter in nics)
            {
                var adapterName = adapter.Name;

                var adapterDescription = adapter.Description;
                var NetworkInterfaceType = adapter.NetworkInterfaceType;
                //if (adapterName == "本地连接")
                {
                    PhysicalAddress address = adapter.GetPhysicalAddress();
                    byte[] bytes = address.GetAddressBytes();

                    for (int i = 0; i < bytes.Length; i++)
                    {
                        MACIp += bytes[i].ToString("X2");

                        if (i != bytes.Length - 1)
                        {
                            MACIp += "-";
                        }
                    }
                }
            }

            return MACIp;
        }
    }
}
